package org.pidan.basic.designModel.prototype;

import lombok.Data;

import java.util.ArrayList;

/**
 * {@code @description}: TODO
 * {@code @author}: huangyuxin
 * {@code @date}: 2023-11-17
 */
@Data
public class User implements Cloneable {

    private String name;

    private String password;

    private ArrayList<String> phones;

    protected User clone() {

        try {
            User user = (User) super.clone();
            //重点，如果要连带引用类型一起复制，需要添加底下一条代码，如果不加就对于是复制了引用地址
            //设置深复制
            user.phones = (ArrayList<String>) this.phones.clone();
            return user;
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
